package com.qf.boot2202day03.exhandler;

import com.qf.boot2202day03.vo.ResultVo;
import com.qf.boot2202day03.vo.ReturnVo;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice   // 全局异常处理器类 ，返回的是json数据
public class GlobalExHandler {

    @ExceptionHandler(ParamNullException.class)
    public ReturnVo handleParamNullEx(ParamNullException e){

        final Integer code = e.getCode();
        final String msg = e.getMsg();

        return ReturnVo.fail(msg);

    }


    @ExceptionHandler(Exception.class)  // 需要处理的异常类型是什么
    public ResultVo handleEx(Exception e){
        return ResultVo.fail(e.getMessage());
    }




}
